package com.leyou.item.controller;

import com.leyou.dto.pojo.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类controller
 *
 * @author xxx
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父节点查询商品类目
     *
     * @param pid 父id
     * @return List<CategoryDTO>
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryByParentId(
            @RequestParam(name = "pid", defaultValue = "0") Long pid) {
        return ResponseEntity.ok(categoryService.queryListByParent(pid));
    }

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryByIds(@RequestParam("ids") List<Long> idList){
        return ResponseEntity.ok(categoryService.queryByIds(idList));
    }
}
